package com.test.learnkotlin.test

import android.util.Log
import com.test.learnkotlin.bean.Person
import com.test.learnkotlin.extension.print

/*
    https://juejin.cn/post/7171031370511155231
 */
fun main(){
    val personsList = listOf(
        Person("kotlin",1),
        Person("Java",2),
        Person("Android",3),
        Person("Python",4),
        Person("SpringBoot",5)
    )

//    persons.print { "${it.name} , ${it.id}" }.let { Log.i("==",it) } //Log.i android
    println(personsList)
    //[Person(name=kotlin, id=1, age=20, address=null), Person(name=Java, id=2, age=20, address=null), Person(name=Android, id=3, age=20, address=null), Person(name=Python, id=4, age=20, address=null), Person(name=SpringBoot, id=5, age=20, address=null)]
    println("-----------------------------------------------------")

    // 用 Kotlin 的扩展函数+泛型+高阶函数
    personsList.print { "${it.name} , ${it.id}" }.let { println(it) }
    /*
        [
            kotlin , 1,
            Java , 2,
            Android , 3,
            Python , 4,
            SpringBoot , 5,
        ]
     */


    println("------------------------ personsMap -----------------------------")
    val personsMap = mapOf(
        "kotlin" to 1,
        "Java" to 2,
        "Android" to 3,
        "Python" to 4
    )

    personsMap.print { it.toString() }?.let { println(it) }
    /*
        {
            [kotlin] = 1
            [Java] = 2
            [Android] = 3
            [Python] = 4
        }
     */
}